﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;

namespace Qadir.Net
{
    /// <summary>
    /// A wrapper around a System.Net.HttpWebResponse that exposes properties for easy handling of an HTTP response.
    /// </summary>
    public class Responder : QadirObject<HttpWebResponse>
    {
        public Responder(HttpWebResponse baseResponse)
            :base(baseResponse)
        {
            BaseObject = baseResponse;
        }

        /// <summary>
        /// A binary representation of the response data.
        /// </summary>
        public byte[] ResponseBytes
        {
            get
            {
                byte[] result = new byte[BaseObject.ContentLength];
                BaseObject.GetResponseStream().Read(result, 0, result.Length);
                return result;
            }
        }

        /// <summary>
        /// A string representation of the response data.
        /// </summary>
        public string ResponseText
        {
            get
            {
                using (StreamReader sr = new StreamReader(BaseObject.GetResponseStream()))
                {
                    return sr.ReadToEnd();
                }
            }
        }
    }
}
